<template>
  <div class="transferAccount">
    <div class="headerBox">
      <van-nav-bar
        title="申请提现"
        right-text="提现记录"
        left-arrow
        @click-left="goBack"
        @click-right="onClickRight"
      ></van-nav-bar>
    </div>
    <div class="formBox">
      <van-cell title="当前可用" :value="balance+'FIL'" class="subAllot" />
      <van-field v-model="ruleForm.amount" type="number" label="提现金额"  @keydown="handleInput" placeholder="请输入提现金额" oninput="if(value.length>8)value=value.slice(0,10)" input-align="right" />
      <!-- <div class="cellInput">
        <span class="label">提现金额</span>
        <MyNumberInput :point="2" :max="999999999" placeholder="请输入提现金额" v-model.number="ruleForm.amount"></MyNumberInput>
      </div> -->
      <div class="addressBox">
        <van-field v-model="ruleForm.address" label="提现地址" placeholder="请输入提现地址" input-align="right" />
        <img src="@/assets/img/wallet/icon_saomiao@2x.png" alt="" class="scannerIcon" @click="scannerFunc">
        <p></p>
      </div>
      <p class="tip">*单次提现手续费{{serviceCharge}}FIL</p>
    </div>
    <div class="handlerBox" v-show="isOriginHei">
      <p class="handlerBtn handlerBtn1" @click="submit">提现申请</p>
    </div>
  </div>
</template>

<script>
import FNScanner from "../FNScanner.js";
import positionBtn from "../positionBtn.js";
import MyNumberInput from '../../components/MyNumberInput';
export default {
  mixins: [FNScanner,positionBtn],
  data() {
    return {
      balance:30,
      ruleForm:{
        amount:'',
        address:'',
      },
      serviceCharge:0.01
    }
  },
  components: {
        MyNumberInput //注册 
  },
  created(){
    this.getConfigList()
  },
  watch: {
    scannerContent(val) {
      this.ruleForm.address=val
    }
  },
  methods:{
    async getConfigList(){
      let res = await this.$http.configList({key:'WITHDRAWAL_HANDLING_FEE_KEY'});
      if (res) {
        this.serviceCharge=res.data.configValue
      }
    },
    handleInput(e){
      e.target.value = (e.target.value.match(/^\d*(\.?\d{0,1})/g)[0]) || null
    },
    onClickRight(){
      this.$router.push({name:'withdrawRecord'})
    },
    goBack(){
      this.$router.go(-1)
    },
    async getUserFilInfo() {
      this.$toast.loading({
          message: '加载中...',
          forbidClick: true,
          duration:5000
      });
      let res = await this.$http.userWalletBalance({walletAddr:this.walletSelect.walletAddr});
      if (res) {
        this.balance = this.$selfFunc.toNonExponential(res.data.balance,8)
        this.$toast.clear()
      } else{
        this.$toast.clear()
      }
    },
    async submit(){
      if(Number(this.balance)==0){
        this.$toast('当前fil数量不足')
        return
      } else if(!this.ruleForm.amount) {
        this.$toast('请输提现金额')
        return
      } else if(Number(this.ruleForm.amount)>Number(this.balance)) {
        this.$toast('提现金额超过当前可用FIL数')
        return
      }  else if (!this.ruleForm.address) {
        this.$toast('请输入提现地址')
        return
      }
      this.$toast.loading({
          message: '提交中...',
          forbidClick: true,
          duration:5000
      });
      let res = await this.$http.userWalletApply({withdrawMoney:this.ruleForm.amount,withdrawAddress:this.ruleForm.address});
      if (res) {
        this.ruleForm.amount=""
        this.ruleForm.address=""
        this.$toast.clear()
        this.$toast('提交成功')
      }
    },
    scannerFunc(){
      this.FNScannerFunc()
    },
  }
};
</script>

<style scoped>
.transferAccount{
  background: #fff;
  min-height: 100vh;
}
.handlerBox{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-top: 2px solid #F1F1F1;
}
.handlerBtn{
  height: 0.82rem;
  line-height: 0.82rem;
  border-radius: 0.41rem;
  text-align: center;
  color: #fff;
  font-size:0.34rem;
  margin: 0 auto;
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}
.handlerBtn1{
  width: 6.94rem;
  background: #F6741F;
}
.addressBox{
  position: relative;
}
.scannerIcon{
  position: absolute;
  width: 0.4rem;
  height: 0.4rem;
  top:0rem;
  right: 0rem;
  padding: 0.22rem 0.28rem 0.2rem 0.2rem;
  box-sizing: content-box;
}
.tip{
  color: #F30F0F;
  padding-left: 16px;
  padding-top: 10px;
}
</style>
<style>
.subAllot .van-cell__value{
  font-size: 0.28rem;
  color: #F6741F !important;
  font-weight: bold;
}
.addressBox input{
  padding-right: 0.55rem;
}
</style>